import sys

sys.setrecursionlimit(100000)

m = dict()
sm = dict()
sm[1] = 1


def get_sum_digital(x):
    v = m.get(x, None)
    if v:
        return v
    else:
        m[x] = sum([int(i) for i in str(x)])
        return m[x]


def get_sum_sq(v):
    if sm.get(v, None):
        return sm[v]
    else:
        sm[v] = get_sum_sq(v - 1) + get_sum_digital(v)
        return sm[v]


n = int(input())

for i in range(n):
    v = int(input())
    print(get_sum_sq(v))
